<template>
    <view class="page">
        <navigator open-type="navigate" v-if="is_login" class="g-line f-border1px margin-t" url="/pages/user/settings/change_head_pic?type=1">
            <text class="u-line-title">修改头像</text>
            <arrow size="40" color="#ccc" direction="right"></arrow>
        </navigator>
		<navigator open-type="navigate" v-if="is_login" class="g-line f-border1px" url="/pages/user/settings/change_name?type=1">
		    <text class="u-line-title">修改真实姓名</text>
		    <arrow size="40" color="#ccc" direction="right"></arrow>
		</navigator>
		<navigator open-type="navigate" v-if="is_login" class="g-line f-border1px" url="/pages/user/settings/change_name?type=2">
		    <text class="u-line-title">修改基本信息</text>
		    <arrow size="40" color="#ccc" direction="right"></arrow>
		</navigator>
		<navigator open-type="navigate" v-if="is_login&&data.mobile == ''" class="g-line f-border1px" :url="'/pages/user/settings/change_phone'">
		    <text class="u-line-title">绑定手机号码</text>
		    <arrow size="40" color="#ccc" direction="right"></arrow>
		</navigator>
		<navigator open-type="navigate" v-if="is_login&&!union_id" class="g-line f-border1px" url="/pages/user/settings/bindWx">
		    <text class="u-line-title">绑定微信</text>
		    <arrow size="40" color="#ccc" direction="right"></arrow>
		</navigator>
		<navigator open-type="navigate" v-if="is_login&&data.mobile != ''" class="g-line f-border1px" :url="'/pages/user/settings/set_checkpwd?type=1'">
		    <text class="u-line-title">修改手机号码</text>
		    <arrow size="40" color="#ccc" direction="right"></arrow>
		</navigator>
        <navigator open-type="navigate" v-if="is_login" class="g-line f-border1px" url="/pages/user/settings/address/address?settype=setting">
            <text class="u-line-title">地址管理</text>
            <arrow size="40" color="#ccc" direction="right"></arrow>
        </navigator>
        <navigator open-type="navigate" v-if="isGoodsTpye&&is_login" class="g-line f-border1px" url="/pages/user/settings/change_level">
            <text class="u-line-title">我的分享人</text>
            <arrow size="40" color="#ccc" direction="right"></arrow>
        </navigator>
		<navigator open-type="navigate" v-if="is_login" class="g-line f-border1px" url="/pages/user/settings/change_pay_password">
		    <text class="u-line-title">修改登录密码</text>
		    <arrow size="40" color="#ccc" direction="right"></arrow>
		</navigator>
        <navigator open-type="navigate" v-if="isGoodsTpye&&is_login" class="g-line f-border1px" url="/pages/user/settings/bank_card/bank_card">
            <text class="u-line-title">银行卡管理</text>
            <arrow size="40" color="#ccc" direction="right"></arrow>
        </navigator>
		<navigator open-type="navigate" v-if="isGoodsTpye&&is_login" class="g-line f-border1px" url="/pages/user/settings/set_checkpwd">
		    <text class="u-line-title">修改支付密码</text>
		    <arrow size="40" color="#ccc" direction="right"></arrow>
		</navigator>
		<navigator open-type="navigate" class="g-line f-border1px margin-t" :url="'/pages/common/article?id='+article.registration_agreement">
		    <text class="u-line-title">恒朗源来用户使用及隐私政策</text>
		    <arrow size="40" color="#ccc" direction="right"></arrow>
		</navigator>
		<navigator open-type="navigate" class="g-line f-border1px margin-t" :url="'/pages/common/article?id='+buy_article">
		    <text class="u-line-title">享宝协议</text>
		    <arrow size="40" color="#ccc" direction="right"></arrow>
		</navigator>
		
		<navigator open-type="navigate" class="g-line f-border1px margin-t" url="/pages/user/settings/copyright">
		    <text class="u-line-title">关于</text>
		    <arrow size="40" color="#ccc" direction="right"></arrow>
		</navigator>
		
        <button v-if="is_login" class="btn" @tap="logout">退出登录</button>

    </view>
</template>


<script>
	import henglang from '@/common/common.js';
	
    export default {
        data() {
            return {
                data: {
                    nickname: '点击登录',
                    head_pic_text: '../../../static/images/no_login.png',
                },
				is_login:false,
				isGoodsTpye: henglang.isGoodsTpye(),
				article:uni.getStorageSync('article'),
				buy_article:uni.getStorageSync('buyAgreementData').buy_agreement_article,
				union_id:uni.getStorageSync('userInfo').union_id
            };
        },
        methods: {
            back() {
                uni.switchTab({
                	url:'/pages/jewel/user/user'
                })
            },
            toLogin() {
				let url = henglang.checkLogin()?'/pages/user/settings/change_name':'/pages/user/login';
				uni.navigateTo({
				    url: url
				});
            },
            logout() {
                let that = this;
                if (!henglang.checkLogin()) { // 未登录
                    uni.navigateTo({
                        url: '/pages/user/login?type=1'
                    })
                } else { // 已登录
					uni.removeStorage({
						key:'token',
						success() {
							uni.removeStorage({
								key: 'userInfo',
								success() {
									henglang.showToast('退出成功',500);
									that.is_login = false
									uni.switchTab({
										url:'/pages/jewel/user/user'
									})
								}
							});
						}
					})
                }
            }
        },
        onShow() {
			
            let that = this;
            if (henglang.checkLogin()) { // 登录
                uni.getStorage({
                    key: 'userInfo',
                    success(res) {
                        that.data = res.data;
                    }
                })
				this.is_login = true;
                this.logoutText = '退出登录';
            } else { // 未登录
				this.is_login = false;
                this.logoutText = '点击登录';
            }
        },
		onBackPress(options) {  
		    if (options.from === 'navigateBack') {  
		        return false;  
		    }  
		    this.back();  
		    return true;  
			
		}, 
    }
</script>

<style>
    /* 公共样式 */
    .margin-b {
        margin-bottom: 10px;
    }
	.margin-t {
	    margin-top: 10px;
	}
    .page {
        background: #f6f6f6;
        min-height: 100vh;
    }

    /* 用户信息 */
    .g-user-info {
        display: flex;
        align-items: center;
    }

    .g-user-pic {
        width: 126upx;
        height: 126upx;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: hidden;
        border-radius: 100px;
        margin-right: 10px;
    }

    .g-user-wrap {
        margin: 10px 0;
    }

    .g-user-info image {
        width: 126upx;
    }

    /* 设置条 */
    .g-line {
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
        background: #fff;
        padding: 15px 10px;
        /* margin-bottom: 1px; */
    }

    .u-line-title {
        color: #6a6a6a
    }


    .btn {
        margin: 120upx 0 20px 5%;
        background: #d71311;
        color: #fff;
        width: 90%;
        border-radius: 100px;
        padding: 12px 0;
        box-shadow: 0 0 10px rgba(0, 0, 0, .2);
        font-size: 38upx;
    }
</style>
